package com.cwz.file.controller;


import com.cwz.core.result.R;
import com.cwz.file.service.UserFileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * <p>
 * 用户文件表 前端控制器
 * </p>
 *
 * @author Wen
 * @since 2023-06-28
 */
@RestController
@RequestMapping("/file")
public class UserFileController {
	@Autowired
	private UserFileService userFileService;

	/**
	 * @Description: 上传文件
	 * @Author: Wen
	 * @param files:
	 * @param pathId:
	 * @return: com.cwz.core.result.R<java.util.Map<java.lang.String,java.lang.Object>>
	 **/
	@PostMapping("/upload/{pathId}")
	public R<Map<String, Object>> upload(@RequestParam MultipartFile[] files, @PathVariable Long pathId) {
		return this.userFileService.upload(files, pathId);
	}

	/**
	 * @Description: 下载文件
	 * @Author: Wen
	 * @param fileId:
	 * @param response:
	 * @return: void
	 **/
	@GetMapping("/download/{fileId}")
	public void download(@PathVariable Long fileId, HttpServletResponse response) {
		this.userFileService.download(fileId, response);
	}

	/**
	 * @Description: 删除文件
	 * @Author: Wen
	 * @param fileId:
	 * @return: com.cwz.core.result.R<java.lang.Void>
	 **/
	@DeleteMapping("/{fileId}")
	public R<Void> deleteFile(@PathVariable Long fileId) {
		return this.userFileService.deleteFile(fileId);
	}

	/**
	 * @Description: 查询用户文件
	 * @Author: Wen
	 * @param pathId:
	 * @param fileName:
	 * @param fileType:
	 * @param pageNum:
	 * @param pageSize:
	 * @return: com.cwz.core.result.R<java.util.Map<java.lang.String,java.lang.Object>>
	 **/
	@GetMapping("/list")
	public R<Map<String, Object>> listFile(Long pathId, String fileName, String fileType, Integer pageNum, Integer pageSize) {
		return this.userFileService.listFile(pathId, fileName, fileType, pageNum, pageSize);

	}

	/**
	 * @Description: 分享文件
	 * @Author: Wen
	 * @param fileId:
	 * @return: com.cwz.core.result.R<java.lang.String>
	 **/
	@GetMapping("/share/{fileId}")
	public R<String> shareFile(@PathVariable Long fileId) {
		return this.userFileService.shareFile(fileId);
	}

}

